package com.cool.orchestration.service.impl;

import com.cool.common.model.request.BaseApiRequest;
import com.cool.orchestration.api.ThirdPartyApiService;
import com.cool.orchestration.service.IApiGatewayService;
import com.cool.orchestration.service.IThirdPartyApiServiceFactory;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class ApiGatewayServiceImpl<T extends BaseApiRequest, E> implements IApiGatewayService<T, E>{

    private final Logger logger = LoggerFactory.getLogger(ApiGatewayServiceImpl.class);

    @Resource
    private IThirdPartyApiServiceFactory<T, E> thirdPartyApiServiceFactory;

    @Override
    public E run(T apiRequest) {
        logger.info("API 限流处理。。。");
        // 根据接口名称选择对应的实现类
        String interfaceName = apiRequest.getInterfaceName();
        ThirdPartyApiService<T, E> thirdPartyApiService = thirdPartyApiServiceFactory.getService(interfaceName);
        return thirdPartyApiService.run(apiRequest);
    }
}
